package com.shelpe.services.sinbadgateway.security;

import javax.servlet.http.HttpServletRequest;

import org.springframework.security.core.Authentication;
import org.springframework.security.oauth2.provider.authentication.BearerTokenExtractor;
import org.springframework.security.oauth2.provider.authentication.TokenExtractor;

import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

@Setter
@Slf4j
public class WebTokenExtractor implements TokenExtractor {

	private BearerTokenExtractor proxy;
	private String tokenParameterName;
	
	@Override
	public Authentication extract(HttpServletRequest request) {
		Authentication auth = null;
		if(request.getParameter(tokenParameterName) == null){
			auth = this.proxy.extract(request);
		}else{
			log.debug("ignore to extract the oauth token if token parameter {} is exist", request.getParameter(tokenParameterName));
		}
		return auth;
	}

}
